package com.itheima.controller;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result page(StudentQueryParam param){
        log.info("查询学生: {}", param);
        PageBean pageBean = studentService.studentList(param);
        return Result.success(pageBean);
    }
    @PostMapping
    public Result add(@RequestBody Student student) {
        System.out.println("添加学生: " + student);
        studentService.add(student);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        System.out.println("根据ID查询学生信息: " + id);
        Student student = studentService.selectById(id);
        return Result.success(student);
    }
    @PutMapping
    public Result update(@RequestBody Student student) {
        System.out.println("修改学生信息: " + student);
        studentService.update(student);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids)  {
        System.out.println("批量删除学生: " + ids);
        studentService.delete(ids);
        return Result.success();
    }

    @PutMapping("/violation/{id}/{score}")
    public  Result deal(@PathVariable Integer id,@PathVariable Integer score) {
        System.out.println("处理违纪: " + id);
        studentService.deal(id,score);
        return Result.success();
    }
}

